using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Web;
using PickGold.Charting.Borders3D;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeBorder3DAnnotation_Border3DAnnotation"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class Border3DAnnotation : RectangleAnnotation
	{
		private BorderSkin _borderSkin;

		public Border3DAnnotation()
		{
			base.isRectVisible = false;
			this._borderSkin = new BorderSkin(this);
			this._borderSkin.PageColor = Color.Transparent;
			this._borderSkin.SkinStyle = BorderSkinStyle.Raised;
			base.lineColor = Color.Empty;
		}

		internal override RectangleF GetTextSpacing(out bool annotationRelative)
		{
			annotationRelative = false;
			RectangleF rectangle = new RectangleF(3f, 3f, 3f, 3f);
			if (base.GetGraphics() != null)
			{
				rectangle = base.GetGraphics().GetRelativeRectangle(rectangle);
			}
			if ((((this._borderSkin.SkinStyle != BorderSkinStyle.None) && (base.GetGraphics() != null)) && ((base.Chart != null) && (base.Chart.ChartPicture != null))) && (base.Common != null))
			{
				IBorderType borderType = base.Common.BorderTypeRegistry.GetBorderType(this._borderSkin.SkinStyle.ToString());
				if (borderType != null)
				{
					RectangleF areasRect = new RectangleF(0f, 0f, 100f, 100f);
					borderType.AdjustAreasPosition(base.GetGraphics(), ref areasRect);
					rectangle = new RectangleF(areasRect.X + 1f, areasRect.Y + 1f, (100f - areasRect.Right) + 2f, (100f - areasRect.Bottom) + 2f);
				}
			}
			return rectangle;
		}

		internal override void Paint(Chart chart, ChartGraphics graphics)
		{
			PointF empty = PointF.Empty;
			PointF anchorLocation = PointF.Empty;
			SizeF size = SizeF.Empty;
			this.GetRelativePosition(out empty, out size, out anchorLocation);
			PointF tf3 = new PointF(empty.X + size.Width, empty.Y + size.Height);
			RectangleF ef2 = new RectangleF(empty, new SizeF(tf3.X - empty.X, tf3.Y - empty.Y));
			RectangleF rectangle = new RectangleF(ef2.Location, ef2.Size);
			if (rectangle.Width < 0f)
			{
				rectangle.X = rectangle.Right;
				rectangle.Width = -rectangle.Width;
			}
			if (rectangle.Height < 0f)
			{
				rectangle.Y = rectangle.Bottom;
				rectangle.Height = -rectangle.Height;
			}
			if ((!float.IsNaN(rectangle.X) && !float.IsNaN(rectangle.Y)) && (!float.IsNaN(rectangle.Right) && !float.IsNaN(rectangle.Bottom)))
			{
				if (base.Common.ProcessModePaint)
				{
					RectangleF absoluteRectangle = graphics.GetAbsoluteRectangle(rectangle);
					if ((absoluteRectangle.Width > 30f) && (absoluteRectangle.Height > 30f))
					{
						graphics.Draw3DBorderRel(this._borderSkin, rectangle, this.BackColor, this.BackHatchStyle, string.Empty, ChartImageWrapMode.Scaled, Color.Empty, ChartImageAlignmentStyle.Center, this.BackGradientStyle, this.BackSecondaryColor, this.LineColor, this.LineWidth, this.LineDashStyle);
					}
				}
				base.Paint(chart, graphics);
			}
		}

		[Browsable(false), SerializationVisibility(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeAnnotationType"), Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), SRCategory("CategoryAttributeMisc")]
		public override string AnnotationType
		{
			get
			{
				return "Border3D";
			}
		}

		[Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), DefaultValue((string)null), TypeConverter(typeof(LegendConverter)), NotifyParentProperty(true), SRDescription("DescriptionAttributeBorderSkin"), SRCategory("CategoryAttributeAppearance")]
		public BorderSkin BorderSkin
		{
			get
			{
				return this._borderSkin;
			}
			set
			{
				this._borderSkin = value;
				this.Invalidate();
			}
		}
	}
}

